<?php

class TLoader_File extends TLoader{
    function getTest($path){
        if(is_file($path)){
            $dom = new DOMDocument();
            $dom->load($path);
            $suite_name = $dom->getElementsByTagName('suite')->item(0)->getAttribute('name');
            $test_suite = new Test_Suite($suite_name);
            $cases = $dom->getElementsByTagName('case');
            foreach($cases as $case){
                $case_name = $case->getAttribute('name');
                $case_type = $case->getAttribute('type');
                $location  = $case->getAttribute('location');
                $params    = $case->getElementsByTagName('param');
                $parray    = Array();
                foreach($params as $param){
                    $key = $param->getAttribute('key');
                    $value = $param->getAttribute('value');
                    $parray[$key] = $value;
                }
                $asserts   = $case->getElementsByTagName('assert');
                $asarray   = Array();
                foreach($asserts as $assert){
                    $method = $assert->getAttribute('method');
                    $expectation = trim($assert->getElementsByTagName('expectation')->item(0)->nodeValue);
                    if(!isset($asarray[$method])){
                        $asarray[$method] = Array();
                    }
                    $asarray[$method][] = $expectation;
                }
                switch($case_type){
                    case 'interface':
                        $test = new Test_Case_Interface_BuiltIn($case_name,$location,$parray,$asarray);
                        $test_suite->add($test);
                        break;
                    default :
                        break;
                }
            }
            return $test_suite;
        } else {
            return new Test_Suite_Bad('bad suite','not test case file');
        }
    }
}

?>
